/**
 * @description:
 * @author: siwukun
 * @date: 2022/05/30
 */
package com.itheima.stock.controller;


import com.github.pagehelper.PageInfo;
import com.itheima.stock.common.domian.UserPageDomain;
import com.itheima.stock.pojo.SysUser;
import com.itheima.stock.service.UserService;
import com.itheima.stock.vo.req.LoginReqVo;
import com.itheima.stock.vo.resp.LoginRespVo;
import com.itheima.stock.vo.resp.PageResult;
import com.itheima.stock.vo.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 登录
     *
     * @param vo 请求数据
     * @return LoginRespVo
     */
//    @PostMapping("/login")
//    public R<LoginRespVo> login(@RequestBody LoginReqVo vo) {
//        return userService.login(vo);
//    }

    /**
     * 生成验证码
     *
     * @return data
     */
    @GetMapping("/captcha")
    public R<Map> generateCaptcha() {
        return userService.generateCaptcha();
    }

    /**
     * 多条件综合查询用户分页信息，条件包含：分页信息 用户创建日期范围
     *
     * @param userPageDomain 模糊查询分页实体类
     * @return
     */

    @PostMapping("/users")
    public R<PageResult<PageInfo>> getPageUserinfo(@RequestBody UserPageDomain userPageDomain) {
        return userService.queryPageUserinfo(userPageDomain);
    }

    @PostMapping("/user")
    public R<String> addUserInfo(@RequestBody SysUser sysUser){
        return userService.addUserData(sysUser);
    }

    /**
     * 更改用户状态
     * @param id 用户id
     * @param status 用户状态码
     * @return 操作结果
     */
//    @PutMapping("/user")
//    public R<String> putUserStatus(@RequestParam String id,@RequestParam Integer status){
//        return userService.upDateUserStatus(id,status);
//    }

}
